package com.nlp.shop.web.core;

import com.jfinal.config.Constants;
import com.jfinal.config.Handlers;
import com.jfinal.config.Interceptors;
import com.jfinal.config.JFinalConfig;
import com.jfinal.config.Plugins;
import com.jfinal.config.Routes;
import com.jfinal.core.JFinal;
import com.jfinal.kit.PropKit;
import com.nlp.shop.web.beetl.BeetlRenderFactory;
import com.nlp.shop.web.controller.CartController;
import com.nlp.shop.web.controller.CategoryController;
import com.nlp.shop.web.controller.IndexController;
import com.nlp.shop.web.interceptor.BootInterceptor;
import com.nlp.shop.web.wx.WeiXin;


/**
 * 
 * @author zyl
 *
 */
public class GlobalConfig extends JFinalConfig {

  @Override
  public void configConstant(Constants me) {
//     PropKit.use("development.properties"); // 开发或测试模式
    PropKit.use("production.properties"); // 生产模式

    me.setMainRenderFactory(new BeetlRenderFactory());

    me.setDevMode(PropKit.getBoolean("sys.dev_model", false));
    me.setEncoding("UTF-8");
    
    WeiXin.setAppId( PropKit.get("appid") );
    WeiXin.setAppSecret( PropKit.get("secret") );
    WeiXin.setHost( PropKit.get("host") );
  }

  @Override
  public void configRoute(Routes me) {
    me.add("/", IndexController.class);
    me.add("/cart", CartController.class,"/cart");
    me.add("/category", CategoryController.class, "/category");
  }

  @Override
  public void configPlugin(Plugins me) {

//    C3p0Plugin c3p0Plugin =
//        new C3p0Plugin(PropKit.get("jdbc.url"), PropKit.get("jdbc.user"), PropKit.get(
//            "jdbc.password").trim());
//    me.add(c3p0Plugin);
//    
//    ActiveRecordPlugin arp = new ActiveRecordPlugin("fcj",c3p0Plugin);
//    me.add(arp);
    
  }
  //全局拦截器
  @Override
  public void configInterceptor(Interceptors me) {
//	  me.add(new BootInterceptor());
  }

  @Override
  public void configHandler(Handlers me) {
	  
  }
  
  public static void main(String[] args) {
    JFinal.start("src/main/webapp", 8080, "/", 50);
  }
  
  @Override
  public void beforeJFinalStop() {
  }
}
